@(categorie_ditte: List[Categoria_Ditta], idLongForm: play.data.Form[IdLong], daCercare: Categoria,categorie: List[Categoria]) 
@import helper._

@main("Cerca Ditta") {
	
	<!-- COMBOBOX with AUTOCOMPLETE -->
	
	 <link rel="stylesheet" href="@routes.Assets.at("autocomplete/jquery-ui-themes-1.10.3/themes/smoothness/jquery-ui.css")" /> 
	 <script src="@routes.Assets.at("javascripts/jquery-1.9.0.min.js")" type="text/javascript"></script>
	 
	 <script src="@routes.Assets.at("tablesorter/jquery.tablesorter.js")" type="text/javascript"></script>
  	 <script src="@routes.Assets.at("autocomplete/jquery-ui.js")"></script>
   <link rel="stylesheet" href="/resources/demos/style.css" />
  <style>
  .custom-combobox {
    position: relative;
    display: inline-block;
  }
  .custom-combobox-toggle {
    position: absolute;
    top: 0;
    bottom: 0;
    margin-left: -1px;
    padding: 0;
    /* support: IE7 */
    *height: 1.7em;
    *top: 0.1em;
  }
  .custom-combobox-input {
    margin: 0;
    padding: 0.3em;
    width: 20em;
  }
  .ui-autocomplete {
		max-height: 200px;
		overflow-y: auto;
		/* prevent horizontal scrollbar */
		overflow-x: hidden;
	}
  </style>
  <script>
  (function( $ ) {
    $.widget( "custom.combobox", {
      _create: function() {
        this.wrapper = $( "<span>" )
          .addClass( "custom-combobox" )
          .insertAfter( this.element );
 
        this.element.hide();
        this._createAutocomplete();
        this._createShowAllButton();
      },
 
      _createAutocomplete: function() {
        var selected = this.element.children( ":selected" ),
          value = selected.val() ? selected.text() : "";
 
        this.input = $( "<input>" )
          .appendTo( this.wrapper )
          .val( value )
          .attr( "title", "" )
          .addClass( "custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left" )
          .autocomplete({
            delay: 0,
            minLength: 0,
            source: $.proxy( this, "_source" )
          })
          .tooltip({
            tooltipClass: "ui-state-highlight"
          });
 
        this._on( this.input, {
          autocompleteselect: function( event, ui ) {
            ui.item.option.selected = true;
            this._trigger( "select", event, {
              item: ui.item.option
            });
          },
 
          autocompletechange: "_removeIfInvalid"
        });
      },
 
      _createShowAllButton: function() {
        var input = this.input,
          wasOpen = false;
 
        $( "<a>" )
          .attr( "tabIndex", -1 )
          .attr( "title", "Mostra tutto" )
          .tooltip()
          .appendTo( this.wrapper )
          .button({
            icons: {
              primary: "ui-icon-triangle-1-s"
            },
            text: false
          })
          .removeClass( "ui-corner-all" )
          .addClass( "custom-combobox-toggle ui-corner-right" )
          .mousedown(function() {
            wasOpen = input.autocomplete( "widget" ).is( ":visible" );
          })
          .click(function() {
            input.focus();
 
            // Close if already visible
            if ( wasOpen ) {
              return;
            }
 
            // Pass empty string as value to search for, displaying all results
            input.autocomplete( "search", "" );
          });
      },
 
      _source: function( request, response ) {
        var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
        response( this.element.children( "option" ).map(function() {
          var text = $( this ).text();
          if ( this.value && ( !request.term || matcher.test(text) ) )
            return {
              label: text,
              value: text,
              option: this
            };
        }) );
      },
 
      _removeIfInvalid: function( event, ui ) {
 
        // Selected an item, nothing to do
        if ( ui.item ) {
          return;
        }
 
        // Search for a match (case-insensitive)
        var value = this.input.val(),
          valueLowerCase = value.toLowerCase(),
          valid = false;
        this.element.children( "option" ).each(function() {
          if ( $( this ).text().toLowerCase() === valueLowerCase ) {
            this.selected = valid = true;
            return false;
          }
        });
 
        // Found a match, nothing to do
        if ( valid ) {
          return;
        }
 
        // Remove invalid value
        this.input
          .val( "" )
          .attr( "title", "'"+value + "' non ha corrispondenze!" )
          .tooltip( "open" );
        this.element.val( "" );
        this._delay(function() {
          this.input.tooltip( "close" ).attr( "title", "" );
        }, 2500 );
        this.input.data( "ui-autocomplete" ).term = "";
      },
 
      _destroy: function() {
        this.wrapper.remove();
        this.element.show();
      }
    });
  })( jQuery );



	$(function() {
	    $( "#id" ).combobox();
  	});

	
  </script>
	
	<table>
	<td>
	@form(routes.Application.home()) {
   			<button type="submit" class="btn btn-success btn-large"><i class="icon-home"></i> Home</button>
    }
	</td>
	<td>
   	<p style="-webkit-text-stroke: #000000 1px; font-size: 39px; color:#3ADF00">CERCA DITTE</p>
   	</td>
   	</table>
   	
   	
   	<table border=0>
   	@form(routes.Ditte.findDittaByCategoria()) {
   	<tr>
   	<td>
   	
		@select(idLongForm("id"), options(Categoria.options),'_label -> "Seleziona Categoria:")

   	</td>
   	<td>
    	<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button type="submit" class="btn btn-large" title="Cerca tutte le ditte associate alla categoria selezionata"><i class="icon-search"></i> </button>
    }
    </td>
    </tr>
    </table>
   	
   		<h3>Ditte correllate con la categoria "@daCercare.denominazione"</h3>
   		
   	    <table class="tablesorter table table-bordered table-hover table-condensed">
   	    <thead> 
        <tr class="success"><th><b>Nome</b></th><th><b>Categoria</b></th><th><b>Descrizione</b></th><th><b>Tetto Budget</b></th><th><b>Protocollo</b></th></tr>
        </thead>
        <tbody>
        @for(categoria_ditta <- categorie_ditte) {
                @if(categoria_ditta.categoria.id == daCercare.id && categoria_ditta.ditta.anno >= Calendar.getInstance().get(Calendar.YEAR)){
                <tr class="info"> 
                
                <td>@categoria_ditta.ditta.nome</td> <td>@categoria_ditta.categoria.categoria</td> <td>@categoria_ditta.categoria.denominazione</td> <td>@categoria_ditta.classifica.tettoBudget</td> <td>@categoria_ditta.protocollo</td>
                
                <td>
                                        <div class="btn-group">
                                        <a class="btn btn-danger btn-mini" title="Elimina Ditta" href="@routes.Ditte.deleteDitta(categoria_ditta.ditta.id)" onclick="return confirm('Are you sure?');"><i class="icon-trash"></i></a>
                                        <a class="btn btn-warning btn-mini" title="Modifica Ditta" href="@routes.Ditte.editDitta(categoria_ditta.ditta.id)"><i class="icon-pencil"></i></a>
                                        <a class="btn btn-info btn-mini" title="Aggiungi collegamento ad una categoria/classifica" href="@routes.Ditte.aggiungiCategoria(categoria_ditta.ditta.id)"><i class="icon-plus"></i></a>
                                
                                </div>
                </td>
                </tr> 
             }       
        }
    	</tbody>
    </table>
    
   
    
}